<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

use Illuminate\Support\Facades\Route;

//API 路由
Route::group(['namespace' => 'Api', 'as' => 'api.'], function() {
    Route::post('login', 'AuthenticateController@login')->name('login');
    Route::post('logout', 'AuthenticateController@logout')->name('logout');
    Route::any('login/mini-program', 'AuthenticateController@loginByWeixinMiniProgram')->name('login.mini-program');
    Route::any('login/account-password', 'AuthenticateController@loginByAccountPassword');
    Route::post('register', 'AuthenticateController@register')->name('register');
    Route::post('register/mini-program', 'AuthenticateController@registerByWeixinMiniProgram');
    Route::post('register/account-password', 'AuthenticateController@registerByAccountPassword');
});

$middleware = ['auth:api'];
if (config('app.env') == 'local')
{
//    $middleware = [];
}
Route::group(['middleware' => $middleware, 'as' => 'api.'], function() {
    Route::group(['namespace' => 'Api'], function() {
        Route::any("test", "TestController@test")->name('test');
        Route::resource('user', 'UserController');
        Route::resource('forum', 'ForumController');
        Route::resource('forumtaxonomy', 'ForumtaxonomyController');
        Route::resource('topic', 'TopicController');
        Route::get('topic-sticky', 'TopicController@sticky');
        Route::get('topic-config', 'TopicController@config');
        Route::get('topic-my', 'TopicController@my');
        Route::resource('comment', 'CommentController');
        Route::get('comment-my', 'CommentController@my');
        Route::resource('attachment', 'AttachmentController');
        Route::resource('like', 'LikeController');

        Route::resource('notification', 'NotificationController');
        Route::put('notification/read/{id}', 'NotificationController@markAsRead');
        Route::get('scores', 'ScoreController@index');
        Route::post('form-id', 'FormIdController@store');
        Route::get('search', 'SearchController@search');
        Route::resource('swiper', 'SwiperController');
        Route::resource('order', 'OrderController');
        Route::post('order-checkout', 'OrderController@checkout')->name('order.checkout');

        Route::post('token/refresh', 'AuthenticateController@refreshToken')->name('token.refresh');
        Route::post('logout', 'AuthenticateController@logout')->name('logout');
    });
    Route::get('area/province', 'CommonController@province')->name('area.province');
    Route::get('area/city', 'CommonController@city')->name('area.city');
    Route::get('area/district', 'CommonController@district')->name('area.district');
    Route::get('area/list-by-pid/{pid}', 'CommonController@listAreaByPid')->name('area.list-by-pid');
    Route::get('area/province-city-district', 'CommonController@provinceCityDistrict')->name('area.province-city-district');
    Route::any('upload/image', 'UploadController@image')->name("upload.image");
    Route::get('upload/token', 'UploadController@token')->name("upload.token");
    Route::get('upload/token/cloudinary', 'UploadController@CloudinaryToken');
});